﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Protocols
{
    public static class Utils
    {
        private static DateTime? BaseTime = null;

        public static long GetTimestamp(DateTime now)
        {
            if (BaseTime == null)
            {
                BaseTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Utc);
            }

            return (long)(now - BaseTime.Value).TotalSeconds;
        }

        public static DateTime GetTime(long TimeStamp)
        {
            if (BaseTime == null)
            {
                BaseTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Utc);
            }

            return BaseTime.Value.AddTicks(TimeStamp * 10000000);
        }
    }
}
